package com.fpt.mockproject.j21.absd.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.NaturalId;

@Entity
@Table(name = "COUNTY")
@DynamicUpdate(value = true)
public class County {
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "CountyID", nullable = false, updatable = false, unique = true)
	private Long countyID;
	
	@NaturalId
	@Column(name = "CountyName", nullable = false, unique = true)
	private String countyName;
	
	@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "CountryID")
	private Country country;
	
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "county")
	private Set<PostCode> postCodes = new HashSet<>(0);
	
	@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, mappedBy = "county")
	private Set<Town> towns = new HashSet<>(0);
	
	public Set<Town> getTowns() {
		return towns;
	}
	public void setTowns(Set<Town> towns) {
		this.towns = towns;
	}
	public Set<PostCode> getPostCodes() {
		return postCodes;
	}
	public void setPostCodes(Set<PostCode> postCodes) {
		this.postCodes = postCodes;
	}
	public Country getCountry() {
		return country;
	}
	public void setCountry(Country country) {
		this.country = country;
	}
	public Long getCountyID() {
		return countyID;
	}
	public void setCountyID(Long countyID) {
		this.countyID = countyID;
	}
	public String getCountyName() {
		return countyName;
	}
	public void setCountyName(String countyName) {
		this.countyName = countyName;
	}
}
